GBML manual / Drawing

animation_play

Starts one of this object’s animations, by the name you gave it in the Animations window: animation_play("walk"). If that animation is already playing it keeps going, so you can call this every step. animation_play("attack", true) starts it over from its first frame, even if it is already playing.

Works differently on Game Boy - Animations play as on the Advance, with smaller limits: a frame lasts up to 650 sixtieths of a second, a frame has at most 4 boxes of each kind, and a game has up to 255 animations.

Works differently on Game Boy Color - Animations play as on the Advance, with smaller limits: a frame lasts up to 650 sixtieths of a second, a frame has at most 4 boxes of each kind, and a game has up to 255 animations.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

animation_play(name, restart = false)

Arguments

NameType
nameanimation
restartbool (can be left out; then it is false)

Returns

Nothing.

Description

Starts one of this object's animations, by the name you gave it in the Animations window. Write the name in quotes.

If that animation is already playing, nothing happens, so you can call it every step without it starting over. Add true to start it from its first frame even so: animation_play("attack", true).

The name is checked when the game is built. A name the object does not have is a message that lists the animations it does have (and says which one you probably meant). An object plays its own animations and its parent's.

While an animation plays it sets sprite and frame for you, so leave those alone. animation_stop gives them back.

A play-once animation that has finished counts as not playing, so calling animation_play again plays it again.

Example

if (btn_pressed(BTN_A)) {
    animation_play("attack", true);
}

Swinging starts over each time A is pressed.

On the GBA

The name is checked when you build: a name the object does not have is a message that lists the ones it does. The animation changes `sprite` and `frame` for you, so leave those alone while it plays; animation_stop() hands them back. A once animation that has finished counts as not playing, so calling it again plays it again. The frame’s sound and event happen in the animation step of the frame, after Step, not inside this call.

See also: Animationsanimation_stopanimation_currentanimation_finishedanimation_endanimation_event